﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using sexhealth.console.service.post.vo;
using System.Collections;
using sexhealth.console.service.post;
using System.Text;

public partial class usercontrol_RightPostList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["chid"] != null)
            {
                int chid = int.Parse(Request["chid"]);
                PostService postService = new PostService();
                ChannelVO ch = postService.DaoGetVOById<ChannelVO>(chid);
                StringBuilder sb = new StringBuilder();
                if (ch.ParentId == 0)
                {
                    IList<ChannelVO> childChannelList = postService.GetChannelList(chid);
                    if (childChannelList.Count > 0)
                    {
                        IList<PostVO> postList = postService.GetPostList(childChannelList[0].ChannelNo);
                        foreach (PostVO post in postList)
                        {
                            sb.Append("<tr>");
                            sb.Append("<td height='36' bgcolor='#E1E1E1'>");
                            sb.Append(" <a href='postdetail.aspx?chid=" + childChannelList[0].ChannelNo + "&pid=" + post.PostNo + "' class='b04'>" + post.Title + "</a>");
                            sb.Append(" </td>");
                            sb.Append("</tr>");
                        }
                        ltlPostList.Text = sb.ToString();
                        ltlSubChannelName.Text = childChannelList[0].Name;
                        ltlLocationName.Text = childChannelList[0].Name;
                    }
                }
                else
                {
                    IList<PostVO> postList = postService.GetPostList(chid);
                    foreach (PostVO post in postList)
                    {
                        sb.Append("<tr>");
                        sb.Append("<td height='36' bgcolor='#E1E1E1'>");
                        sb.Append(" <a href='postdetail.aspx?chid=" + chid + "&pid=" + post.PostNo + "' class='b04'>" + post.Title + "</a>");
                        sb.Append(" </td>");
                        sb.Append("</tr>");
                    }
                    ltlPostList.Text = sb.ToString();
                    ltlSubChannelName.Text = ch.Name;
                    ltlLocationName.Text = ch.Name;
                }
            }
        }
    }
}
